#ifndef SY_FIFO_H_
#define SY_FIFO_H_

#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
# define SY_CPP(x) x
# if __cplusplus >= 201103L
#  define SY_THROW noexcept
# else
#  define SY_THROW throw ()
# endif
#else
# define SY_CPP(x)
# define SY_THROW
#endif

SY_CPP(extern "C" {)


#define sy_malloc malloc
#define sy_free free


/* SY_INLINE is used for functions in header files */
#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
# define SY_INLINE static inline
#else
# define SY_INLINE static
#endif

#ifdef SY_API_STATIC
# define SY_API_DECL static
#else
# define SY_API_DECL extern
#endif


typedef enum SY_FIFO_RET {
    SY_FIFO_OK = 0,
    SY_FIFO_UNERROR,
    SY_FIFO_INVALID,
    SY_FIFO_NULL
}SY_FIFO_RET;

typedef struct sy_fifo_base {
    u_int32_t data;
    struct sy_fifo_base* next;
}sy_fifo_base;

typedef struct sy_fifo_handle {
    const char* fifo_name;
    size_t fifo_size;
    size_t fifo_number;
    bool fifo_lock;
    sy_fifo_base* H;
    sy_fifo_base* L;
}sy_fifo_handle;

SY_API_DECL SY_FIFO_RET sy_fifo_init(sy_fifo_handle* fifo_handle);
SY_API_DECL SY_FIFO_RET sy_fifo_push(sy_fifo_handle* fifo_handle, u_int32_t data);
SY_API_DECL SY_FIFO_RET sy_fifo_output(sy_fifo_handle* fifo_handle, u_int32_t* data);


SY_CPP(})

#endif  /* SY_FIFO_H_ */
